const Koa=require('koa')
const path=require('path')
const fs=require('fs')
const Router=require('koa-router')
const multer=require('koa-multer')

const app=new Koa()

const loginRouter=new Router({prefix:'/login'})
        //创建写入流
 
//获取路径和上传文件的后缀名
const storage=multer.diskStorage({
    destination:'./uploades',
    filename:(req,file,cb)=>{
       cb(null,'a'+path.extname(file.originalname))
    }

})
//创建upload
const upload=multer({
    storage
})
//解析上传文件
loginRouter.post('/',upload.single('file2'),(ctx,next)=>{
       console.log(ctx.req.file)
       ctx.body="上传成功"
})
//注册路由
app.use(loginRouter.routes())



app.listen(8000,()=>{
    console.log('服务器启动成功')
})